// import { defineConfig } from 'vite'
import { UserConfigExport, ConfigEnv } from 'vite'
import path from 'path'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import Less2CssVariablePlugin from 'antd-less-to-css-variable'
import { getThemeVariables } from 'ant-design-vue/dist/theme'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default ({ command }: ConfigEnv): UserConfigExport => {
  const { resolve } = path
  let prodMock = true
  return {
    define: {
      'process.env': {},
      // Suppress warning
      __INTLIFY_PROD_DEVTOOLS__: false,
    },
    resolve: {
      alias: [
        {
          find: 'vue-i18n',
          replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
        },
        {
          find: /^@\//,
          replacement: resolve(__dirname, './src') + '/',
        },
        { find: /^~/, replacement: '' },
      ],
    },
    server: {
      host: '0.0.0.0',
      port: 5173,
      proxy: {
        '/bridgeApi': {
          target: 'http://8.153.68.82:9000',
          ws: false,
          changeOrigin: true,
        },
        '/modelApi': {
          target: 'http://8.153.68.82:9000',
          ws: false,
          changeOrigin: true,
        },
      },
      // hmr: {
      //   overlay: false
      // }
    },
    css: {
      preprocessorOptions: {
        less: {
          // DO NOT REMOVE THIS LINE
          javascriptEnabled: true,
          plugins: [new Less2CssVariablePlugin()],
          modifyVars: getThemeVariables(),
          // modifyVars: {
          //   hack: `true; @import 'ant-design-vue/dist/antd.less'`, // antd.dark.less
          // }
        },
      },
      postcss: {},
    },
    plugins: [
      vue(),
      vueJsx(),
      createSvgIconsPlugin({
        // 指定需要缓存的图标文件夹
        iconDirs: [resolve(__dirname, 'src/assets/icons')],
        // 指定symbolId格式
        symbolId: 'icon-[name]',
      }),
      Components({
        resolvers: [AntDesignVueResolver({ importStyle: false })],
      })
    ],
  }
}
